#include <cstdio>
#include <queue>

using namespace std;

int n, m, vp, vs, vt, x1, y1, x2, y2;
char map[ 25 ][ 25 ];
int d[ 1001 ];
queue<int> q;

void init( )
{
    int i;
    scanf("%d%d%d", &vp, &vs, &vt);
    for ( i = 0; i < n; i++ )
        scanf("%s", map[ i ]);
    scanf("%d%d%d%d", &x1, &y1, &x2, &y2);
    for ( i = 0; i < n * m; i++ )
        d[ i ] = 0xfffffff;
    d[ x1 * m + y1 ] = 0;
    q.push( x1 * m + y1 );
}

bool relax( int u, int v, int w )
{
    if ( u < 0 || u >= n || v < 0 || v >= m )
        return false;
    if ( map[ u ][ v ] == '@' )
        return false;
    int c;
    if ( map[ u ][ v ] == '#' )
        c = vp;
    if ( map[ u ][ v ] == '.' )
        c = vs;
    if ( map[ u ][ v ] == 'T' )
        c = vt;
    if ( d[ u * m + v ] > w + c )
    {
        d[ u * m + v ] = w + c;
        return true;
    }
    return false;
}

void spfa( )
{
    int p, x, y;
    while ( !q.empty( ) )
    {
        p = q.front( );
        q.pop( );
        x = p / m;
        y = p % m;
        if ( relax( x - 1, y, d[ p ] ) )
            q.push( ( x - 1 ) * m + y );
        if ( relax( x + 1, y, d[ p ] ) )
            q.push( ( x + 1 ) * m + y );
        if ( relax( x, y - 1, d[ p ] ) )
            q.push( x * m + y - 1 );
        if ( relax( x, y + 1, d[ p ] ) )
            q.push( x * m + y + 1 );
    }
    if ( d[ x2 * m + y2 ] == 0xfffffff )
        puts("-1");
    else
        printf("%d\n", d[ x2 * m + y2 ]);
}

int main( )
{
    int scase = 1;
    while ( scanf("%d%d", &n, &m) != EOF )
    {
        init( );
        printf("Case %d: ", scase++);
        spfa( );
    }
    return 0;
}
